package com.byxy.managerial.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.alibaba.fastjson.JSON;
import com.byxy.managerial.service.DepartmentService;

public class DepartmentDeleteAction {
	private Integer id;

	@Resource
	private DepartmentService departService;

	public void deleteDepart() throws IOException {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Map<String, Object> map = new HashMap<String, Object>();
		boolean isDelete = departService.delete(id);
		map.put("isDelete", isDelete);
		PrintWriter pw = response.getWriter();
		String str = JSON.toJSONString(map);
		pw.write(str);
		pw.flush();
		pw.close();
	}

	private int[] ids;

	public void deleteAll() throws IOException {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Map<String, Object> map = new HashMap<String, Object>();
		if (ids != null) {
			for (int i = 0; i < ids.length; i++) {
				departService.delete(ids[i]);
			}
		}
		map.put("isDelete", true);
		PrintWriter pw = response.getWriter();
		String str = JSON.toJSONString(map);
		pw.write(str);
		pw.flush();
		pw.close();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

}
